﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HiLand.Utility.Entity;

namespace DotNET4Study
{
    class MemberWiseCloneStudy
    {
        public static void Execute()
        {
            A a = new A();
            a.Age = 20;
            B b = new B();
            b.a = a;

            B memberwiseB = b.Clone();


            B hiB = EntityHelper.Clone(b);

            B deepB = EntityHelper.DeepClone(b);


            b.a.Age = 21;
            if (b.a.Age == memberwiseB.a.Age)
            {
                Console.WriteLine("浅表复制的引用信息是共享的");
            }
            else
            {
                Console.WriteLine("浅表复制的引用信息是NO共享的");
            }

            if (b.a.Age == hiB.a.Age)
            {
                Console.WriteLine("Hi复制的引用信息是共享的");
            }
            else
            {
                Console.WriteLine("Hi复制的引用信息是NO共享的");
            }

            if (b.a.Age == deepB.a.Age)
            {
                Console.WriteLine("deep复制的引用信息是共享的");
            }
            else
            {
                Console.WriteLine("deep复制的引用信息是NO共享的");
            }


        }
    }

    [Serializable]
    class A
    {
        public int Age { get; set; }
    }

    [Serializable]
    class B
    {
        public A a { get; set; }

        public B Clone()
        {
            return (B)this.MemberwiseClone();
        }
    }
}
